package com.test.example.controller.sms;

import com.xingluo.tools.exception.SmsException;
import com.xingluo.tools.sms.AliSmsClient;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@Tag(name="短信服务")
@RestController
public class SmsController {

    // 主配置项的AliSmsClient，或者 Map<String, AliSmsClient> aliSmsClients的第一个Bean
    @Resource
    private AliSmsClient aliSmsClient;

    // 若有多个短信模版配置，则使用Map<String, AliSmsClient>的Bean
    @Resource
    private Map<String, AliSmsClient> aliSmsClients;

    @Operation(summary = "发送短信模版", description = "发送短信模板")
    @GetMapping("/sms")
    public String index(@RequestParam("tel") String tel) {
        try{
            // aliSmsClient.sendCode(tel, "123456");
            aliSmsClients.get("sms-name1").sendCode(tel, "123456");
        }catch (SmsException e){
            return e.getMessage();
        }
        return "success";
    }
}
